<?php if (!defined('insite')) die("no access"); 
 if (!$_SESSION["character"])
 {
	if ($_GET["chname"]){$reschar = substr($_GET["chname"],0,10);own_char($reschar,$_SESSION["user"]);$_SESSION["character"] = $reschar;}
	elseif ($_POST["selectedchar"]){$reschar = substr($_POST["selectedchar"],0,10);own_char($reschar,$_SESSION["user"]);$_SESSION["character"] = $reschar; }
	else {echo reset_no_char; die();}
 }
?>
<table align="center" valign="top" class="tableMain" width="70%">
<tr>
	<td class="zagstyle" colspan="2"><?=clinv_title?></td>
</tr>
<form method="POST" action="">
<tr>
	<td  align="center"><input type="submit" name="clbtn" value="Clean inventory" class="t-button"></td>
</tr>
</form>

<?php
	if ($_REQUEST["clbtn"])
	{
		if ($_SESSION["character"] && strlen($_SESSION["character"])>2)
		{
			require "opt.php";
			
			$db = new Connect ($config["ctype"], $config["db_host"], $config["db_name"], $config["db_user"], $config["db_upwd"],$config["odbc_driver"],$config["debug"]); 

			$need_cl = validate(substr($_SESSION["character"],0,10));
			$check = $db->fetcharray($db->query("SELECT AccountID FROM Character WHERE Name='".$need_cl."'"));
			
			if ($_SESSION["user"] == $check["AccountID"]) 
			{
				
				$uqery = "UPDATE Character SET Inventory=0x".$config["inventory"]." WHERE AccountID='".$need_cl."'";
				if ($_POST["opt1"]=='warehouse') $uqery.="; UPDATE warehouse SET Items=NULL WHERE AccountID='".$check["AccountID"]."'";
				$db->query($uqery);
				unset($uqery);
				echo "<tr><td class='succes' colspan='2'>All is Ok!</td></tr>";
			} 
			else echo "<tr><td class='warnms' colspan='2'>Character NOT exists or wrong parametrs</td></tr>";
		}
	}
?>
</table>